package com.mymobile.showcase.mobile;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import com.hmsproject.common.HMSUtil;
import com.hmsproject.db.util.HMSDBUtil;

@ManagedBean
@ViewScoped
public class SignUpUserView {

	public String getEmailAddress() {
		return emailAddress;
	}
	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	private String firstName;
	private String lastName;
	private String emailAddress;
	private String password;
	
	
	
	/*public void signUpUser(ActionEvent event)
	{
		try{
			long verificationCode = HMSDBUtil.getInstance().signUpUser(this);
			HMSUtil.getInstance().sendMail(this.getEmailAddress(), verificationCode);
			System.out.println("User Signed up " + verificationCode + "    " + this.getEmailAddress());
			
		}catch(Exception e){
			FacesContext.getCurrentInstance().addMessage(null, 
			        new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), null));	
		}
		
	
	}*/
	
	public String signUpUser(){
		try{
			long verificationCode = HMSDBUtil.getInstance().signUpUser(this);
			HMSUtil.getInstance().sendMail(this.getEmailAddress(), verificationCode);
			System.out.println("User Signed up " + verificationCode + "    " + this.getEmailAddress());
			
		}catch(Exception e){
			FacesContext.getCurrentInstance().addMessage(null, 
			        new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), null));	
			return null;
		}
		return "/user/signUpMessage.xhtml?faces-redirect=true";
	}
	
	public static void main(String args[]){
		
		SignUpUserView signUpUserView = new SignUpUserView();
		signUpUserView.setEmailAddress("arumugampillaia@gmail.com");
		signUpUserView.setPassword("arumugam");
		signUpUserView.signUpUser();
		
	}
}
